//
//  DBColPropertyPair.m
//  etionMisc
//
//  Created by wjxfhxy on 5/10/13.
//  Copyright (c) 2013 GuangZhouXuanWu. All rights reserved.
//

#import "DBColPropertyPair.h"

@interface CDBColPropertyPair ()
{
    NSString *_szTable;

    NSString *_szCol;

    NSString *_szAscol;
}
@end

@implementation CDBColPropertyPair

@synthesize szCol = _szCol;

@synthesize szAscol = _szAscol;

@synthesize szTable = _szTable;

- (id)initWithCol:(NSString *)szCol Property:(NSString *)szProperty
{
    self = [super init];

    super.idKey = szCol;
    self.szCol = szCol ;
    super.idValue = szProperty;

    return self;
}

- (id)initWithTable:(NSString *)szTable col:(NSString *)szCol asCol:(NSString *)szAscol property:(NSString *)szProperty
{
    [self initWithCol:szCol Property:szProperty];

    super.idKey = szAscol;
    self.szCol = szCol;
    self.szAscol = szAscol;
    self.szTable = szTable;

    return self;
}

+ (CDBColPropertyPair *)DBColPropertyPairWithCol:(NSString *)szCol property:(NSString *)szProperty
{
    return [[[CDBColPropertyPair alloc] initWithCol:szCol Property:szProperty] autorelease_mm];
}

+ (CDBColPropertyPair *)DBColPropertyPairWithCol:(NSString *)szCol property:(NSString *)szProperty propertyType:(ENSObjectPropertyType)propertyType
{
    CDBColPropertyPair *p = [[[CDBColPropertyPair alloc] initWithCol:szCol Property:szProperty] autorelease_mm];
    p.propertyType = propertyType;
    return p;
}

+ (CDBColPropertyPair *)DBColPropertyPairWithTable:(NSString *)szTable col:(NSString *)szCol asCol:(NSString *)szAscol property:(NSString *)szProperty
{
    return [[[CDBColPropertyPair alloc] initWithTable:szTable col:szCol asCol:szAscol property:szProperty] autorelease_mm];
}

- (void)setIdKey:(id)idKey
{
    [super setIdKey:idKey];
    self.szCol = _key;
}

- (NSString *)TableAsCol
{
    if (_szTable== nil|| _szAscol == nil)
        return _szCol;
    return [NSString stringWithFormat:@"%@.%@ as %@", _szTable, _szCol, _szAscol];
}

- (id)copyWithZone:(NSZone *)zone
{
    CDBColPropertyPair *pair = (CDBColPropertyPair *) [[super copyWithZone:zone] init];
    pair.szAscol = _szAscol;
    pair.szCol = _szCol;
    pair.propertyType = _propertyType;
    pair.szTable = _szTable;

    return pair;
}

- (void)dealloc
{
    [_szTable release_mm];
    [_szAscol release_mm];
    [_szCol release_mm];
    superdealloc_mm;
}

@end

